package com.mind.adjust.controller;

import com.mind.common.core.page.PageDomain;
import com.mind.common.core.page.TableSupport;
import com.mind.system.domain.AjRuleDetail;
import com.mind.adjust.service.AjRuleDetailService;
import com.mind.common.utils.poi.ExcelUtil;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.web.page.TableDataInfo;
import com.mind.common.log.annotation.Log;
import com.mind.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能审核模块/审核模块/规则明细管理
 *
 * @author makejava
 * @DocView.PathPrefix {{host}}/api/adjust
 * @Date 2024-07-11 20:40:13
 */
@RestController
@RequestMapping("adjust/ruleDetail")
public class AjRuleDetailController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private AjRuleDetailService ajRuleDetailService;

    /**
     * 获取规则明细列表
     *
     * @param ruleDetail 筛选条件
     * @return com.mind.system.domain.AjRuleDetail
     */
    @PreAuthorize("@ss.hasPermi('adjust:ruleDetail:list')")
    @Log(title = "规则明细列表", businessType = BusinessType.QUERY)
    @GetMapping("/list")
    public TableDataInfo list(AjRuleDetail ruleDetail)
    {
        PageDomain pageDomain = startPage();
        if (pageDomain.getPageSize()==0) {
            return getDataTable(ajRuleDetailService.selectRuleDetailListVo(ruleDetail));
        }
        return getDataTable(ajRuleDetailService.selectRuleDetailList(ruleDetail));
    }

    /**
     * 规则明细导出
     * @param ruleDetail 筛选条件
     * @return 结果
     */
    @Log(title = "规则明细导出", businessType = BusinessType.EXPORT)
//    @RequiresPermissions("adjust:ruleDetail:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, AjRuleDetail ruleDetail)
    {
        List<AjRuleDetail> list = ajRuleDetailService.selectRuleDetailList(ruleDetail);
        ExcelUtil<AjRuleDetail> util = new ExcelUtil<AjRuleDetail>(AjRuleDetail.class);
        util.exportExcel(response, list, "规则明细数据");
    }

    /**
     * 根据ID获取规则明细详情
     * @return com.mind.system.domain.AjRuleDetail
     */
//    @RequiresPermissions("adjust:ruleDetail:query")
    @GetMapping(value = "/{ruleDetailId}")
    public AjaxResult getInfo(@PathVariable Long ruleDetailId)
    {
        return success(ajRuleDetailService.selectRuleDetailById(ruleDetailId));
    }

    /**
     * 新增规则明细
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('adjust:ruleDetail:add')")
    @Log(title = "规则明细新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AjRuleDetail ruleDetail)
    {
        int i = ajRuleDetailService.insertRuleDetail(ruleDetail);
        if (i>0) {
            return success(ruleDetail);
        }
        return toAjax(i);
    }

    /**
     * 规则明细复制
     * @return 结果
     */
    @Log(title = "规则明细复制", businessType = BusinessType.INSERT)
    @PostMapping("/copy")
    public AjaxResult copy(@Validated @RequestBody AjRuleDetail ruleDetail)
    {
        return toAjax(ajRuleDetailService.copy(ruleDetail));
    }

    /**
     * 修改规则明细
     * @return 结果
     */
//    @RequiresPermissions("adjust:ruleDetail:edit")
    @Log(title = "规则明细修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AjRuleDetail ruleDetail)
    {
        return toAjax(ajRuleDetailService.updateRuleDetail(ruleDetail));
    }

    /**
     * 删除规则明细
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('adjust:ruleDetail:remove')")
    @Log(title = "规则明细删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleDetailIds}")
    public AjaxResult remove(@PathVariable Long[] ruleDetailIds)
    {
        return toAjax(ajRuleDetailService.deleteRuleDetailByIds(ruleDetailIds));
    }


}


